package com.haima.sage.bigdata.api.frame.condition;

import com.fasterxml.jackson.annotation.JsonCreator;
import com.fasterxml.jackson.annotation.JsonValue;
import com.haima.sage.bigdata.api.common.NameUtils;

public enum OperatorType {
    AND("and"), OR("or"), NOT("not"),

    Eq("eq"), Ne("ne"), Gt("gt"), Ge("ge"), Lt("lt"), Le("le"), EqIgnoreCase("eq-ignore-case"),
    Regex("regex"),

    Empty("empty"), NotEmpty("not-empty"), Contains("contains"),
    NotContains("not-contains"), StartWith("start-with"), EndWith("end-with");

    //自定义字段
    private String value;

    //构造方法
    OperatorType(String value) {
        this.value = value;
    }

    @JsonValue
    public String getValue() {
        return value;
    }

    @JsonCreator
    public static OperatorType newInstance(String type) {
        type = NameUtils.trans(type);
        for (OperatorType item : values()) {
            String tmp = NameUtils.trans(item.getValue());
            if (tmp.equals(type)) {
                return item;
            }
        }
        return null;
    }
}
